package cn.szzsi._admin;

import cn.szzsi.common.model.CustomerService;
import cn.szzsi.common.model.SiteConfig;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;

import java.util.Date;

public class CustomerServiceController extends BaseAdminController<CustomerService>{
    public void view(){
        String shopId=getAttr("shopId");//商户id
        CustomerService customerService=CustomerService.dao.getByShopId(shopId);
        setAttr("customerService",customerService);
        render("customer_service_view.html");
    }

    public void updateForm(){
        String shopId=getAttr("shopId");//商户id
        CustomerService customerService=CustomerService.dao.getByShopId(shopId);
        setAttr("customerService",customerService);
        render("customer_service_input.html");
    }

    public void update(){
        String shopId=getAttr("shopId");//商户id
        CustomerService newcustomerService=getModel(CustomerService.class);
        System.out.println(newcustomerService);
        CustomerService customerService=CustomerService.dao.getByShopId(shopId);
        if(customerService!=null){
            newcustomerService.setId(customerService.getId());
            newcustomerService.setUpdateTime(new Date());
            newcustomerService.update();
        }else{
            newcustomerService.setId(StrKit.getRandomUUID());
            newcustomerService.setCreateTime(new Date());
            newcustomerService.setShopId(shopId);
            newcustomerService.save();
        }
        //customerService.set
        renderJson(Ret.ok("info","修改成功!").set("url","view"));
    }

    public static void main(String[] args) {
        System.out.println(StrKit.getRandomUUID());
    }
}
